SHANGHAI — He Junwei traveled about 100 miles on a high-speed train to wait an hour for a cup of coffee.

Mr. He was one of hundreds of Chinese caffeine fiends gathered to visit what essentially serves as a tribute built by Starbucks in their honor. The American company on Wednesday opened its largest store in the world in Shanghai, a 29,000-square-foot sanctuary staffed by 400 employees.

The giant cafe represents the big bet it has placed on a country that until only recently much preferred tea. Starbucks has opened more than 3,000 stores in the country and plans to have 5,000 in four years.

The company said it opens a store in the country at a rate of one every 15 hours.

Inside the Starbucks Reserve Roastery in the city’s center, customers got a close look at how the brown stuff is made.

Pipes carried raw beans to roasters, then to a two-story-tall bronze vessel decorated with hundreds of traditional Chinese seals and patterns.

From there, the beans were piped to a crew of dozens of baristas. Some hand-brewed the coffee using vacuum coffee makers. Like other locations in China, the cafe also sells tea and food.

The store demonstrates the faith — and the money — Starbucks is pouring into China.

China is now one of Starbucks’s major revenue drivers at a time when other foreign companies are complaining about the country’s business environment.

Yum Brands, the owner of Taco Bell and Pizza Hut, spun off its China unit, in part, because of concerns over its ability to grow there. Others, like McDonald’s and Coca-Cola, have also been pulling back from China.

But while other companies have run up against barriers, Starbucks has managed to invest heavily. It pays higher wages than many competitors, and has offered housing allowances and health care benefits.

The company’s efforts have meant the ability to build trust in China.

On Wednesday, that was evidenced by the scores of people waiting to get in.

The opening — held in the cavernous space in which the din of beans rattling through pipes and baristas heating coffee competed with techno music — was designed for people like Mr. He.

“Sometimes I brew at home,” he said, “but it feels lonely.”

A 22-year-old logistics worker in the city of Hangzhou, he also made the trip to add to his collection of Starbucks-themed cups.

“Though many older Chinese like tea, I just like coffee,” said Mr. He. “As the old saying goes, once love has begun, it never ends.”